package qdu.rg012.myrecyclerview;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import java.util.ArrayList;
import java.util.List;

import qdu.rg012.myrecyclerview.Model.BookBean;
/**
 * 1.数据源、数据结构
 *     1.1 准备一个List存储对应item的数据内容,泛型为BookBean
 *     1.2 准备数据模型
 * 2. 准备Adapter
 *    1.1 定义内部类继承RecyclerView.Adapter
 *    1.2 创建adpter对象，并设置显式布局
 * 3. 调用setAdapter
 */
public class MyrecycV extends Activity {
    List<BookBean> mybooklist;
    MyRecyclerAdapter myadp;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ly_myrecycv);

        initdata();
        //if(mybooklist != null)
            //myadp = new MyRecyclerAdapter(mybooklist);


        String []urls = {
                "http://cst.qdu.edu.cn/__local/E/53/78/E4301A41E234B96C0D06F9F12D7_6AADC796_DEB5D.png",
                "http://cst.qdu.edu.cn/__local/6/A7/BA/627F2C89EDDDA53677406C29994_E8571138_D341C.png",
                "http://cst.qdu.edu.cn/__local/7/9E/55/3DE9B8F38DDDE767E15D68E9CAF_A866DAAA_2CD32.png",
                "http://cst.qdu.edu.cn/__local/2/29/18/F3B57BFF63F3D2788563ECBA27B_815B9B5D_39E7F.png",
                "http://cst.qdu.edu.cn/__local/5/F2/C2/A09899D62ED193C30E56A50EBDA_8BA257A8_3B849.png",
                "http://cst.qdu.edu.cn/__local/5/C2/14/F9ED3870999CE663EDF285BAF24_3E50C44F_30C7A.png",
                "http://cst.qdu.edu.cn/__local/7/E3/C6/7A4B54AEB51E1A2EB492A726F62_3ED93572_42250.png"
        };
        myadp = new MyRecyclerAdapter(urls, this);

//        LinearLayoutManager lmng = new LinearLayoutManager(this);
//        lmng.setOrientation(LinearLayoutManager.VERTICAL);
        //GridLayoutManager gmng = new GridLayoutManager(this,3);
        StaggeredGridLayoutManager sgmng = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        RecyclerView myrecyclerview = (RecyclerView) findViewById(R.id.recview_book);
        myrecyclerview.setLayoutManager(sgmng);//设置recyclerview的布局。
                                               // lmng:线性布局;gmng:Grid布局; Sgmng:交错网格布局

        myrecyclerview.setAdapter(myadp);
    }

    private void initdata() {
        mybooklist = new ArrayList<BookBean>();

        BookBean book1 = new BookBean("daodejing", R.mipmap.ddj);
        mybooklist.add(book1);
        BookBean book2 = new BookBean("guiguzi", R.mipmap.ggzlz);
        mybooklist.add(book2);
        BookBean book3 = new BookBean("gaolaozhuang",R.mipmap.glz);
        mybooklist.add(book3);
        BookBean book4 = new BookBean("huangdineijing", R.mipmap.hdnj);
        mybooklist.add(book4);
        BookBean book5 = new BookBean("hongloumeng", R.mipmap.hlm);
        mybooklist.add(book5);
        BookBean book6 = new BookBean("jianai", R.mipmap.ja);
        mybooklist.add(book6);
        BookBean book7 = new BookBean("nahan",R.mipmap.nhph);
        mybooklist.add(book7);
        BookBean book8 = new BookBean("qinaide",R.mipmap.qadmsr);
        mybooklist.add(book8);
    }
}
